import { defineStore } from 'pinia'
import { webStorage } from '@/utils/webStorage'
import { ACCESS_TOKEN } from '@/mutation-type'
export const useUserStore = defineStore('user', {
  state: () => {
    return { user: null }
  },
  actions: {
    setUser(data) {
      this.user = data
    },
    getUser() {
      let user = webStorage.ls.get(ACCESS_TOKEN)
      return this.user ? this.user : user
    },
    logout() {
      return new Promise((resove, reject) => {
        webStorage.ls.remove(ACCESS_TOKEN)
        this.user = null
        resove()
      })
    },
  },
})
